package com.wisdytech.linkdcs.partLife.action;


import com.wisdytech.common.handler.ResourceMatchingService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageInfo;
import com.wisdytech.common.bean.Filter;
import com.wisdytech.common.bean.StandardResult;
import com.wisdytech.common.bean.StandardTableResult;
import com.wisdytech.common.utils.BaseUtil;
import com.wisdytech.linkdcs.partLife.dto.PartStorageSaveDTO;
import com.wisdytech.linkdcs.partLife.dto.PartStorageSearchDTO;
import com.wisdytech.linkdcs.partLife.service.IPartStorageRecordService;
import com.wisdytech.linkdcs.partLife.vo.PartStorageRecordVO;
import com.wisdytech.linkdcs.system.model.SysUser;

import java.io.IOException;
import java.text.ParseException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;

/**
 * <p>
 *  备件出入库记录前端控制器
 * </p>
 *
 * @author chenbin
 * @since 2018-06-05
 */
@Controller
@RequestMapping("/part/partStorageRecord")
public class PartStorageRecordController {
	
    /**
     * 注入备件信息iPartService
     */
    @Autowired
    @Qualifier("iPartStorageRecordService")
    private IPartStorageRecordService iPartStorageRecordService;
    @Autowired
    @Qualifier("resourceMatchingService")
    private ResourceMatchingService resourceMatchingService;
    @RequestMapping("/index")
    public String index(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "lifeCycle/partLifeCycle/partStorageRecord";
    }
    
    @RequestMapping("/search/index")
    public String search(Model model, HttpServletRequest httpRequest){
        this.resourceMatchingService.getResourceName(httpRequest,model);
        return "lifeCycle/partLifeCycle/partStorageSearch";
    }
    
    /**
     * 保存备件出入库信息
     * @param partStorageRecord 备件出入库
     * @param session 
     * @return 保存结果集
     * @throws ParseException 
     */
    @RequestMapping(value = "/savepartStorage/save.mvc")
    @ResponseBody
    public StandardResult savepartStorage(PartStorageSaveDTO partStorageSaveDTO,HttpSession session) throws ParseException {
        SysUser sysUser = BaseUtil.getCurrentUser();
        String userId = sysUser.getPkId();
    	iPartStorageRecordService.savepartStorage(partStorageSaveDTO,userId);
        return  StandardResult.getSuccessResult();
    }
    
    /**
     * 分页条件查询备件出入库列表信息
     * @param partStorageSearchDTO 查询条件对象
     * @param filter 分页参数
     * @return 备件出入库管理列表信息
     * @throws IOException 
     */
    @RequestMapping(value = "/listPartStorageByFilter/get.mvc")
    @ResponseBody	
    public StandardTableResult<PartStorageRecordVO> listPartStorageByFilter(PartStorageSearchDTO partStorageSearchDTO,Filter filter) throws IOException{
    	PageInfo<PartStorageRecordVO> partStorageRecords =this.iPartStorageRecordService.listPartStorageByFilter(partStorageSearchDTO,filter);
        return new StandardTableResult<PartStorageRecordVO>(partStorageRecords.getTotal(),partStorageRecords.getList());
    }
}

